﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="{$cfg_site_description}" />

<title>{$value[0]['title']}|{$cfg_site_name}</title>
{template 'header'}
<style type="text/css">

form.cmxform label.error, label.error {
	color: red;
}
div.error { display: none; font-size:10px;}
input {	border: 1px solid black; }
input:focus { border: 1px dotted black; }
input.error { border: 1px dotted red; }
form label { width:300px;}
</style>
<body>
<div id="buy917_wrap">  
    <div id="buy917_header">
    	<div id="buy917_logo"><a href="index.php">Buy917</a></div>
        <div class="buy917_header_banner">
        	<div class="buy917_header_topbanner">
				{template 'login_line'} <!-- login_line.html 登入/註冊按鈕 --> 
				<?php include("admin/event.php")?>
            </div>
          	<div class="buy917_header_select">
            	<div class="buy917_header_city">
                	 {if !empty($_cityid)}
                    <div class="guides">
                        <div class="city">
                            <h2>{$_cityname}</h2>
                        </div>
                        <div id="guides-city-change" class="change">切換城市</div>
                        <div id="guides-city-list" class="city-list">
                            <ul>
                            {loop $_citylist $v}
                                <li {if $v['cid']==$_cityid}class="current"{/if}><a href="index.php?cityid={$v['cid']}">{$v['cityname']}</a></li>
                            {/loop}
                            </ul>                   
                        </div>
                    </div>
                    {/if}	
                </div>
                <div class="buy917_header_group">
                	{template 'headergroup'}	
                </div>
            </div>
       </div>
    </div><!-- buy917_header -->
  
    {template 'menu_nav'} <!-- menu 導覽頁 --> 
       
    <div id="buy917_middle">
        	<div class="buy917_grouplist_top"></div>      
            <div class="buy917_grouplist_body"> 
                 <h2>您的訂單</h2>
        		  <div id="content">
						  <div id="deal-buy" class="box">
							<div class="box-top"></div>
							<div class="box-content">
							  <div class="head">
							   
							  </div>
							  <div class="sect">
								<table width="90%" align="center" class="order-table" >
								  <tr>
									<th bgcolor="#CCCCCC" class="deal-buy-desc" width="50%">項目</th>
									{if $v['subtitle']}<th bgcolor="#CCCCCC" class="deal-buy-desc" width="15%" >分店資訊</th>{/if}
									<th bgcolor="#CCCCCC" class="deal-buy-quantity">數量</th>
									<th colspan="2" bgcolor="#CCCCCC" class="deal-buy-multi">價格</th>
									<th colspan="3" bgcolor="#CCCCCC" class="deal-buy-equal">總價</th>
								  </tr>

								  <form id="orderForm" action="orderpay.php" method="post">

                      {loop $value $v}
                      {if $v['title'] != ""}
                      								  
								  <tr>
									 <td class="deal-buy-desc">{mb_strimwidth($v['title'],0,200,'...','UTF-8')}</td>
									{if $v['subtitle']}<td class="deal-buy-desc">{$v['subtitle']}</td>{/if}
                                    {if 1>2}
                                    <td class="deal-buy-desc" align="center">{php $localData = (split(';',$v['local']))}
                                    {$localData[$locals]} <input type="hidden" name="local" value="{$localData[$locals]}" /></td>
                                    	{/if}
									<td align="center" class="deal-buy-quantity">{$v['num']}</td>
									<td align="center" class="deal-buy-multi">x</td>
									<td align="center" class="deal-buy-price" id="deal-buy-price"><span class="money">$</span>{$v['shop_price']}</td>
									<td align="center" class="deal-buy-equal">=</td>
									<td align="center" class="deal-buy-total" id="deal-buy-total"><span class="money">$</span>{echo $v['num']*$v['shop_price']}</td>
								  </tr>									
								
								  {/if}
                {/loop}
								  <tr class="order-total">
									<td class="deal-buy-desc"><strong>應付總額</strong></td>
                                    {if $v['subtitle']}<th bgcolor="#CCCCCC" class="deal-buy-desc" width="15%" >分店資訊</th>{/if}
									<td align="center" class="deal-buy-quantity"></td>
									<td align="center" class="deal-buy-multi"></td>
									<td align="center" class="deal-buy-price"></td>
									<td align="center" class="deal-buy-equal">=</td>
									<td align="center" class="deal-buy-total"><span class="money">$</span>{echo $totalPrice}</td>
								  </tr>
								</table>
								<div class="paytype">
								  
								  {if $value[0]['gtypeid']==1}
								  
									<div class="order-check-form ">
									  <p class="choose-pay-type" style="margin-bottom:10px; clear:both;">請填寫配送信息：</p>
									  <style type="text/css">
											.tb{}
											.tb td{ padding:10px}
											.inp{border:1px solid #89B4D6;
													font-size:14px;
													padding:3px 4px;
													width:280px;
												}
												.red {
														color:#CC0000;
														font-size:20px;
														font-weight:bold;
														padding:0 0 0 5px;
														}
										</style>										
									  <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tb">
										<tr>
										  <td width="118" align="right" valign="top">收件人：</td>
										  <td >&nbsp;
											<input name="fname" id="fname" type="text" class="inp" value="{$fname}"/></td>
										</tr>
										<tr>
										  <td align="right" valign="top">地址：</td>
										  <td>&nbsp;
											<textarea name="address" id="address" rows="5" class="inp" >{$address}</textarea></td>
										</tr>
										<tr>
										  <td align="right" valign="top">郵遞區號：</td>
										  <td>&nbsp;
											<input name="zip" id="zip" type="text"class="inp"   value="{$zip}"/></td>
										</tr>
										<tr>
										  <td align="right" valign="top">聯絡電話：</td>
										  <td>&nbsp;
											<input name="tel" id="tel" type="text" class="inp"  value="{$tel}"/></td>
										</tr>
										<tr>
										  <td align="right" valign="top">備註：</td>
										  <td>&nbsp;
										  	<textarea name="tmp" id="tmp" rows="5" class="inp" >{$tmp}</textarea></td>
										</tr>
									  </table>
									</div>
									{/if}
									{if $value[0]['freefreight']==0}
									
									<div class="order-check-form ">
									  <p class="choose-pay-type">請選擇配送方式：</p>
									  <table class="order-table">
										<tr>
										  <th class="deal-buy-desc"></th>
										  <th class="deal-buy-desc">快遞名稱</th>
										  <th class="deal-buy-quantity">尺寸(cm)</th>
										  <th class="deal-buy-multi">首價(元)</th>
										  <th class="deal-buy-price">續重(cm)</th>
										  <th class="deal-buy-equal">續價(元)</th>
  										  <th class="deal-buy-time">送達時段</th>
										  <th class="">備註</th>
										</tr>
										{loop $dataarray $n $r}
										<tr>
										  <td><input onclick="countCartTotal();" name="did" type="radio" value="{$r['did']}" checked="{if $delivery==$r['did']}checked{/if}" /></td>
										  <td class="deal-buy-desc">{$r['name']}</td>
										  <td class="deal-buy-quantity">{$r['first_weight']}</td>
										  <td class="deal-buy-multi">{$r['first_fee']}</td>
										  <td class="deal-buy-price">{$r['continue_weight']}</td>
										  <td class="deal-buy-equal">{$r['continue_fee']}</td>
                                          <td class="deal-buy-time">
                                          <select name="receivetime">
                                          <option value="0">不指定</option>
                                          <option value="1">中午前</option>
                                          <option value="2">12時~17時</option>
                                          <option value="3">17時~20時</option>                                          
                                          </select>
                                          </td>
										  <td class="" id="deal-buy-total">{$r['about']}</td>
										</tr>
										{/loop}
									  </table>
									  <div class="clear"></div>
									</div>
									
									
									{/if}
									
									
									
									{if $_USERS['money']>0}
									<div class="order-check-form ">
									  <p class="choose-pay-type">是否使用帳戶餘額支付：目前帳戶餘額：<font color="red">${echo $_USERS['money']?$_USERS['money']:"0"}</font></p>
									  <ul class="typelist">
										<li>
										  <input id="usemymoney" onclick="countCartTotal();" type="checkbox" name="usemymoney" value="1" checked="checked" style="margin-top:10px;"/>
										  <span>選中將使用您的帳戶餘額支付全部或者部份金額！</span>
										</li>

									  </ul>
									  <div class="clear"></div>
									</div>
									{/if}
									
									
									
									<div class="order-check-form " id="payment_div">
									  <p class="choose-pay-type"><b><br />
								      請選擇支付方式：</b></p>
									  <br />
									  <ul class="typelist">
										{loop $payment_list $n $m}
                                        <?php $x++?>
										 <li style="clear:both;">
                                         	<div style="float:left; display:inline-block; margin-right:7px; line-height:111px;">                                           
                                            <input id="check-{$n}" type="radio" name="paytype" value="{$m['value']}" {if $payment==$m['value'] || $x==1} checked="checked" {/if}/></div>
                     						<div style="float:left; display:inline-block; margin-right:7px;"><img src="{$m['logo']}"></div>
                                   		    <div style="float:left; display:inline-block; margin-right:7px; line-height:111px;"> <label for="check-{$n}">{$m['des']}</label></div>
                   						 </li>
										{/loop}
									  </ul>
									  <div class="clear"></div>
									</div>
									
				<div class="clear"></div>
				<div class="getInvoice">
<b>需要發票：</b><input type="checkbox" name="buyInvoice" class="chk" />是	(如無勾選將把發票捐給慈善機構)※註：如有使用回饋金折抵，折抵金額將不列入發票金額中
					<div class="req1">
					 <h3>發票寄送資訊：</h3>
					 <table width="474" border="0" cellspacing="0" cellpadding="10" style="border:0;">
					  <tr>
						<td width="22%">發票樣式：</td>
						<td width="78%">
							<label>
							<input type="radio" name="radio" id="type" value="2" checked="checked" class="chk2"/>
							二聯</label>
							<label>
							<input type="radio" name="radio" id="type2" value="3" class="chk2"/>
							三聯</label>
						</td>
					  </tr>
					</table>
					
					<div class="2form"></div>
						<div class="3form" style="margin-bottom:7px;">
							<table width="474" border="0" cellspacing="0" cellpadding="10" style="background:#eeeeee;">	
								<tr>
									<td>發票抬頭：</td>
									<td><input type="text" name="txtftitle" id="textfield5" /></td>
								</tr>
								<tr>
									<td>統一編號：</td>
									<td><input type="text" name="txtfidnum" id="textfield6" /></td>
								</tr>
						</table>
					</div>

					 <table width="474" border="0" cellspacing="0" cellpadding="10">			
								
									<tr>
									<td>收件人：</td>
									<td><input type="text" name="txtfname" id="textfield" /></td>
									</tr>
									<tr>
									<td>收件人電話：</td>
									<td><input type="text" name="txtftel" id="textfield2" /></td>
									</tr>
									<tr>
									<td>收件人地址：</td>
									<td><input type="text" name="txtfaddress" id="textfield3" /></td>
									</tr>
									<tr>
									<td>備註事項：</td>
									<td><textarea name="txtfps" id="textfield4"></textarea></td>
									</tr>
								</table>
						</div>
					</div>
				<div id="cart_total_box">									
					<div class="order-check-form ">
					<p class="choose-type">費用總計：<span class="red">未獲取</span> </p>
					<p class="choose-body"> 商品總價：未獲取 <br>
					+ 手續費：$未獲取 <br>
					= 應付款金額：<span class="red">$未獲取</span>&nbsp; <br>
					</p>
					<div class="blank"></div>
					</div>
                </div>
				<div class="order-check-form ">
							  <p class="check-act">
                                <input type="hidden" name="orderdetail" value="{$orderdetail}" />
								<input type="hidden" name="oid" value="{$oid}" />
								<input type="hidden" name="num" value="{echo $totalNum}" />
								<input type="hidden" name="gid" value="{$gid}" />
								<input type="hidden" name="order_incharge" value="{echo $order_incharge?$order_incharge:"0"}" />
								<input type="hidden" name="deliveryType" value="" />
								<input type="hidden" name="deliveryComment" value="" />
								<input type="submit" value="確認訂單，付款" class="formbutton" />
								<a href="buy.php?gid={$gid}&oid={$oid}" style="margin-left:1em; color:#f44d04; text-decoration: underline;">返回修改訂單</a> </p>
							</div>
						  </form>
						</div>
					  </div>
					</div>
					<div class="box-bottom"></div>
				  </div>
				</div>
            </div><!-- buy917_grouplist_body -->
            <div class="buy917_grouplist_bottom"></div>
    </div><!-- buy917_middle -->
</div><!-- buy917wrap -->
<!-- footer -->
<script type="text/javascript"> 
jQuery(function($){
	countCartTotal();
});
var usermoney={echo $_USERS['money']?$_USERS['money']:"0"};

var order_incharge = {echo $order_incharge?$order_incharge:"0"};
var goodsType = {$value[0]['gtypeid']};
var totalPrice = {echo $totalPrice}; //{echo $value['shop_price']*$num};
var freefreight  = {$value[0]['freefreight']};
var num={echo $totalNum};
var groupPrice={$value[0]['shop_price']};
var groupweight={$value[0]['weight']};
var delivery=new Array();

//運費初始化到js中
{loop $dataarray $r}
delivery[{$r['did']}]=new Array();
delivery[{$r['did']}]['did']={$r['did']};
delivery[{$r['did']}]['first_weight']={$r['first_weight']};
delivery[{$r['did']}]['continue_weight']={$r['continue_weight']};
delivery[{$r['did']}]['first_fee']={$r['first_fee']};
delivery[{$r['did']}]['continue_fee']={$r['continue_fee']};
{/loop}

//計算訂單中所有費用
function countCartTotal()
{
	var delivery_id = 0;  //配送方式
	var payment_id =  0;   //支付方式
	var alltotalPrice =0;
	var deliveryfee =0 ;
	var countprice=0;
	var usermymoney=0;

	if(freefreight==0 && goodsType==1)
	{
		
		if($("input[name='did']:checked").length > 0)
		{
			delivery_id = $("input[name='did']:checked").val();			
			
			//計算運費			
			//if(groupweight*num < delivery[delivery_id]['first_weight']){
			//	deliveryfee=delivery[delivery_id]['first_fee'];
			//}
			//else{
			//	deliveryfee=delivery[delivery_id]['first_fee']+Math.ceil((groupweight*num-delivery[delivery_id]['first_weight'])/delivery[delivery_id]['continue_weight'])*delivery[delivery_id]['continue_fee'];
			//}
			//新版運費計算方式
			if(num == 1){
				deliveryfee = 100;
			}
			else if(num == 2){
				deliveryfee = 100;
			}else if (num>=3){
				deliveryfee = 100;
			}
			
		}
	}
		
	if($("input[name='paytype']:checked").length > 0)
	payment_id = $("input[name='paytype']:checked").val();
	
	if(0)
	{
		$("input[name='paytype']").attr("checked",false);
	}
	
	//總費用
	alltotalPrice = totalPrice+deliveryfee;
	countprice=alltotalPrice;
	//判斷是否已經支付一部分
	if(order_incharge!=0){
		countprice = alltotalPrice-order_incharge;
	}else{
		countprice = alltotalPrice;
	}
	if(usermoney>0){
	
		if($("#usemymoney").attr("checked")){
			if(usermoney>countprice){
				usermymoney=countprice;
				countprice=0;
				
			}else{
				countprice=countprice-usermoney;
				usermymoney=usermoney;
			}
		
		}
	}
	if(countprice==0){
		$("#payment_div").hide();
	}else{
		$("#payment_div").show();
	}
	
	
	alltotalPrice=alltotalPrice.toFixed(2);
	deliveryfee=deliveryfee.toFixed(2);
	
	reval = "<div class=\"order-check-form \">";
	reval += "<p class=\"choose-type\">費用總計：<span class=\"red\">$"+countprice+"</span> </p>";
	reval += "<p style=\"text-align: right; line-height: 24px;\"> 商品總價：$"+totalPrice+" <br>";
	if(order_incharge!=0)
	{
		reval += "- 已付款：$"+order_incharge+" <br>";
	}
	if(usermoney>0 && $("#usemymoney").attr("checked"))
	{
		if(usermoney>alltotalPrice){
			reval += "- 使用賬戶餘額支付：$"+usermymoney+" <br>";
		}else{
			reval += "- 使用賬戶餘額支付：$"+usermymoney+" <br>";
		}
	}
	
	
	if(freefreight==0 && goodsType==1)
	{

		reval += "+ 運費：$"+deliveryfee+" <br>";
	}
	reval += "= 應付款金額：<span class=\"red\">$"+countprice+"</span>&nbsp; <br>";
	reval += "</p>";
	reval += "<div class=\"blank\"></div>";
	reval += "</div>";

	$("#cart_total_box").html(reval);
		 
}

/* check order infomation */
 {if $value[0]['gtypeid']==1}
 $().ready(function() {
$("#orderForm").validate({

		rules: {			

			fname: {

				required: true,

			},

			address: {

				required: true,

			},

			zip: {
				required: true,
				minlength: 3,
				maxlength: 5

			},

			tel: {

				required: true,

			},

		},

		messages: {

			

			fname: {

				required: "請輸入姓名"

			},

			address: {

				required: "請輸入地址"

			},

			zip: {

				required: "請輸入郵遞區號",

				minlength: "郵遞區號最少三碼",

				maxlength: "郵遞區號最多五碼",

			},

			tel: {
				required: "請輸電話",
			},
			

		}

	});

 });
 {/if}



</script>
<div id="buy917_footer">
	{template 'footer'}	
</div>
</body>
</html>
